home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 July / Chip_2000-07_cd.bin / sharewar / vbshpdfc / Install.exe / VB Shaped Form Creator.CAB / Reversi.frm < prev    next >
Text File  |  1999-12-19  |  11KB  |  241 lines

  1. VERSION 5.00
  2. Begin VB.Form MainWin 
  3.    BorderStyle     =   0  'None
  4.    Caption         =   "Reversi"
  5.    ClientHeight    =   1590
  6.    ClientLeft      =   1530
  7.    ClientTop       =   1950
  8.    ClientWidth     =   4035
  9.    LinkTopic       =   "Form1"
  10.    LockControls    =   -1  'True
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    PaletteMode     =   1  'UseZOrder
  14.    Picture         =   "Reversi.frx":0000
  15.    ScaleHeight     =   106
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   269
  18.    Begin VB.TextBox OutputBox 
  19.       Height          =   315
  20.       Left            =   510
  21.       Locked          =   -1  'True
  22.       TabIndex        =   1
  23.       Top             =   810
  24.       Width           =   3015
  25.    End
  26.    Begin VB.TextBox InputBox 
  27.       Height          =   315
  28.       Left            =   510
  29.       TabIndex        =   0
  30.       Top             =   450
  31.       Width           =   3015
  32.    End
  33.    Begin VB.Image TempHolder 
  34.       Height          =   255
  35.       Left            =   360
  36.       Top             =   120
  37.       Visible         =   0   'False
  38.       Width           =   255
  39.    End
  40.    Begin VB.Image CloseHolder 
  41.       Height          =   210
  42.       Left            =   600
  43.       Picture         =   "Reversi.frx":14BAA
  44.       Top             =   120
  45.       Visible         =   0   'False
  46.       Width           =   240
  47.    End
  48.    Begin VB.Image MinHolder 
  49.       Height          =   210
  50.       Left            =   240
  51.       Picture         =   "Reversi.frx":14E8C
  52.       Top             =   240
  53.       Visible         =   0   'False
  54.       Width           =   240
  55.    End
  56.    Begin VB.Image CloseB 
  57.       Height          =   210
  58.       Left            =   3285
  59.       Picture         =   "Reversi.frx":1516E
  60.       Top             =   150
  61.       Width           =   240
  62.    End
  63.    Begin VB.Image Min 
  64.       Height          =   210
  65.       Left            =   3015
  66.       Picture         =   "Reversi.frx":15450
  67.       Top             =   150
  68.       Width           =   240
  69.    End
  70. End
  71. Attribute VB_Name = "MainWin"
  72. Attribute VB_GlobalNameSpace = False
  73. Attribute VB_Creatable = False
  74. Attribute VB_PredeclaredId = True
  75. Attribute VB_Exposed = False
  76. 'This program is provided as an example of what can be done using
  77. 'VB Shaped Form Creator by Alex Vallat.  It is, of course, freely
  78. 'distributible and usable by all, although why anyone would want to
  79. 'apart from as an example is beyond me.  Someone must did want it
  80. 'it though, as a program to reverse text was requested by a friend
  81. 'of mine.  It might as well go towards something usefull too, so it
  82. 'is now my example project for VB Shaped Form Creator.
  83. '
  84. 'To create this project I first drew out the shape I wanted in
  85. 'VBSFC <http://www.comports.com/AlexV/VBSFC.html> using an oval and
  86. 'a rounded rectangle.  If you want to see and or edit this shape
  87. 'then use VBSFC to load this form.  This was then exported as a
  88. 'bitmap and as a form.  The form was loaded into VB, and the text
  89. 'boxes and image boxes for the buttons were positioned.  A screen-
  90. 'shot of the form (press Alt+Enter) was then pasted into Paint Shop
  91. 'Pro <http://www.jasc.com>.  The BladePro plugin <http://ccn.cs.dal.ca/~aa731/blade.html>
  92. 'was then used to generate the 3D effects, and the finished bitmap
  93. 'saved.  You can look at and edit this bitmap which is Background.bmp
  94. 'included with the source-code.  If I had not wanted the positions
  95. 'of the text boxes in the bitmap to generate the 3D sunken look for
  96. 'them then it would have been easier to use the export as bitmap
  97. 'function of VBSFC to export the shape directly as a bitmap, which
  98. 'I could then open with PSP.
  99. '
  100. 'After preparing the bitmap I set it as the form's background by
  101. 'setting the forms "picture" property to it.  I also took screen-
  102. 'shots of close and minimize buttons both pressed and unpressed
  103. '(using Alt+Enter), and used PSP to crop them to size.  These are
  104. 'also included with the source as _.bmp and x.bmp (unpressed) and
  105. '_p.bmp and xp.bmp (pressed).  The unpressed images were loaded
  106. 'into the image boxes in position for the close and minimize, but
  107. 'the pressed buttons were put into different image boxes which were
  108. 'set to be invisible, and are just for holding the pictures easily.
  109. 'Another invisible image box was added as a holder with no picture.
  110. 'The reversing code, event handlers and actual programming was then
  111. 'put into place.  Interface first, code later...  Shows, doesn't it?
  112.  
  113. '==================================================================
  114.  
  115.  
  116. 'The following code up to where I say it isn't is all generated by
  117. 'VB Shaped Form Creator to produce the shaped form.
  118.  
  119. Option Explicit
  120.  
  121.  
  122. Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
  123. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  124. Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
  125. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  126. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
  127. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  128. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
  129. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  130. Private Declare Function ReleaseCapture Lib "user32" () As Long
  131. Private Type POINTAPI
  132.    X As Long
  133.    Y As Long
  134. End Type
  135. Private Const RGN_AND = 1
  136. Private Const RGN_COPY = 5
  137. Private Const RGN_DIFF = 4
  138. Private Const RGN_OR = 2
  139. Private Const RGN_XOR = 3
  140. Private Function CreateFormRegion() As Long
  141.     Dim ResultRegion As Long, HolderRegion As Long, ObjectRegion As Long, nRet As Long
  142.     Dim PolyPoints() As POINTAPI
  143.     ResultRegion = CreateRectRgn(0, 0, 0, 0)
  144.     HolderRegion = CreateRectRgn(0, 0, 0, 0)
  145.  
  146. 'This procedure was generated by VB Shaped Form Creator.  This copy has
  147. 'NOT been registered for commercial use.  It may only be used for non-
  148. 'profit making programs.  If you intend to sell your program, I think
  149. 'it's only fair you pay for mine.  Commercial registration costs $20,
  150. 'and can be performed online.  See "Registration" item on the help menu
  151. 'for details.
  152.  
  153. 'Latest versions of VB Shaped Form Creator can be found at my website at
  154. 'http://www.comports.com/AlexV/VBSFC.html or you can visit my main site
  155. 'with many other free programs and utilities at http://www.comports.com/AlexV
  156.  
  157. 'Lines starting with '! are required for reading the form shape using the
  158. 'Import Form command in VB Shaped Form Creator, but are not necessary for
  159. 'Visual Basic to display the form correctly.
  160.  
  161. '!Shaped Form Region Definition
  162. '!3,0,0,270,106,0,0,1
  163.     ObjectRegion = CreateEllipticRgn(0 * 15 / Screen.TwipsPerPixelX, 0 * 15 / Screen.TwipsPerPixelY, 270 * 15 / Screen.TwipsPerPixelX, 106 * 15 / Screen.TwipsPerPixelY)
  164.     nRet = CombineRgn(ResultRegion, ObjectRegion, ObjectRegion, RGN_COPY)
  165.     DeleteObject ObjectRegion
  166. '!2,5,196,240,30,8,8,1
  167.     ObjectRegion = CreateRoundRectRgn(196 * 15 / Screen.TwipsPerPixelX, 7 * 15 / Screen.TwipsPerPixelY, 240 * 15 / Screen.TwipsPerPixelX, 30 * 15 / Screen.TwipsPerPixelY, 16 * 15 / Screen.TwipsPerPixelX, 16 * 15 / Screen.TwipsPerPixelY)
  168.     nRet = CombineRgn(HolderRegion, ResultRegion, ResultRegion, RGN_COPY)
  169.     nRet = CombineRgn(ResultRegion, HolderRegion, ObjectRegion, 2)
  170.     DeleteObject ObjectRegion
  171.     CreateFormRegion = ResultRegion
  172. End Function
  173.  
  174. Private Sub Form_Load()
  175.     Dim nRet As Long
  176.     nRet = SetWindowRgn(Me.hWnd, CreateFormRegion, True)
  177.     Me.Left = (Screen.Width - Me.Width) \ 2
  178.     Me.Top = (Screen.Height - Me.Height) \ 3
  179.     'Following lines makes the background picture resize with the form
  180.     'size, for users with Large Fonts turned on.
  181.     Me.Show
  182.     Me.AutoRedraw = True
  183.     Me.PaintPicture Me.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight
  184.     Me.AutoRedraw = False
  185. End Sub
  186. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  187. 'Next two lines enable window drag from anywhere on form.  Remove them
  188. 'to allow window drag from title bar only.
  189.     ReleaseCapture
  190.     SendMessage Me.hWnd, &HA1, 2, 0&
  191. End Sub
  192.  
  193. '===================End of VBSFC Generated Section=================
  194.  
  195. 'Now starts the code for the actual program.  Here this procedure
  196. 'reverses the text typed into the top box, and displays it in the
  197. 'bottom box.  This program was done by request, and no, I don't
  198. 'know why he wanted something to do this, either. :)
  199.  
  200. Private Sub InputBox_Change()
  201.     Dim Counter As Integer, OutputHolder As String
  202.     For Counter = 1 To Len(InputBox.Text)
  203.         OutputHolder = Mid$(InputBox.Text, Counter, 1) + OutputHolder
  204.     Next Counter
  205.     OutputBox.Text = OutputHolder
  206. End Sub
  207.  
  208. 'When the mouse button is pressed over the minimize button it changes to a "pressed" image.
  209.  
  210. Private Sub Min_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  211.     TempHolder.Picture = Min.Picture    'Remember the original picture
  212.     Min.Picture = MinHolder.Picture     'Display the pressed picture, held in MinHolder imagebox
  213. End Sub
  214.  
  215. 'When the mouse button is released, put the button back up, and perform the action.
  216.  
  217. Private Sub Min_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  218.     Min.Picture = TempHolder.Picture    'Put the picture back the way it was (remembered)
  219.     MainWin.WindowState = 1             'Minimize the form
  220. End Sub
  221.  
  222. 'Same here for the close button.  See Min_MouseDown proc. for details
  223.  
  224. Private Sub CloseB_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  225.     TempHolder.Picture = CloseB.Picture
  226.     CloseB.Picture = CloseHolder.Picture
  227. End Sub
  228.  
  229. Private Sub CloseB_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  230.     CloseB.Picture = TempHolder.Picture
  231.     Unload MainWin                      'Exit the form when close is clicked
  232. End Sub
  233.  
  234. 'Select the text of the bottom text box when it is clicked on
  235.  
  236. Private Sub OutputBox_Click()
  237.     OutputBox.SelStart = 0
  238.     OutputBox.SelLength = Len(OutputBox.Text)
  239. End Sub
  240.  
  241.